import Vue from 'vue'
import VueRouter from 'vue-router'
//导入views的一些视图组件
const cart = () => import('@views/cart/Cart.vue')
const home = () => import('@views/home/Home.vue')
const category = () => import('@views/category/Category.vue')
const profile = () => import('@views/profile/Profile.vue')
Vue.use(VueRouter)
//解决点击重复路由报错问题
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}
const routes = [
  // 配置首页重定向
  {
    path: '',
    redirect: '/home'
  }
  // 主页
  , {
    path: '/home',
    component: home
  },
  // 分类
  {
    path: '/category',
    component: category
  },
  // 购物车
  {
    path: '/cart'
    , component: cart
  }
  //我的
  , {
    path: '/profile'
    , component: profile
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
